package com.jiuyou.websocket.util;

import org.joda.time.DateTime;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期工具类
 */

public class DateTimeUtil {

    public static String toDateString(DateTime dateTime){
        return dateTime.toString("yyyy-MM-dd");
    }

    public static String toDateTimeString(DateTime dateTime){
        return dateTime.toString("yyyy-MM-dd HH:mm:ss");
    }

    public static String toTimeString(DateTime dateTime){
        return dateTime.toString("HH:mm:ss");
    }

    /**
     * 昨天
     */
    public static String getYesterdayDateTimeStr(){
        return toDateTimeString(new DateTime().minusDays(1));
    }

    /**
     * 今天
     */
    public static String getTodayDateStr(){
        return toDateString(new DateTime());
    }
    public static Date getTodayDate(){
        return new DateTime(getTodayDateStr()).toDate();
    }
    public static String getNowDateTimeStr(){
        return toDateTimeString(new DateTime());
    }

    /**
     * 明天
     */
    public static String getTomorrowDateStr(){
        return toDateString(new DateTime().plusDays(1));
    }
    public static Date getTomorrowDate(){
        return new DateTime(getTomorrowDateStr()).toDate();
    }

    /**
     * 字符串转日期
     * @param dateStr
     * @param dateFormat
     * @return
     */
    public static Date convertStringToDate(String dateStr,String dateFormat) {

        Date date = null;
        try {
            SimpleDateFormat sif = new SimpleDateFormat(dateFormat);
            date = sif.parse(dateStr);
        } catch (Exception pe) {
        }
        return date;
    }
}
